#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=2e5+10;
int f[N];
int a[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++)cin>>a[i];
        int sizex=pow(2,n);
        for(int i=1;i<=sizex;i++){
            int cnt=0;
            int x=i,idx=0;
            while(x!=0){
                f[++idx]=x%2;
                x/=2;
            }
            for(int j=n;j>=1;j--){
                if(f[j]==1){
                    int l=j-1;
                    while(l>=0&&f[l]!=1)l--;
                    if(a[l]==a[j]){
                        cnt+=a[j];
                    }
                    f[l]=-1,f[j]=-1;
                }
                if(f[j]==0){
                    int l=j-1;
                    while(l>=0&&f[l]!=0)l--;
                    if(a[l]==a[j]){
                        cnt+=a[j];
                    }
                    f[l]=-1,f[j]=-1;
                }
            }
            ans=max(ans,cnt);
        }
        cout<<ans;
        cout<<endl;
    }
    return 0;
}
